if (!window.dw) var dw = {};
if (!window.dw.ajax) dw.ajax = function (options) {
    if (!('url' in options)) {
        alert ('there\'s no url in options!');
    }
    var method = 'GET';
    if ('method' in options) method = options ['method'];

    var isIE = (/MSIE/i).test(navigator.userAgent);
    var request = isIE ? new ActiveXObject ("Microsoft.XMLHTTP") : new XMLHttpRequest ();

    var url = options ['url'];

    function buildParameter (data) {
        var s = '';
        for (var key in data) {
            if (s.length > 0) s += '&';
            s += key + '=' + encodeURIComponent(data [key]);
        }
        return s;
    }

    if (method.toLowerCase() == 'get' && ('data' in options)) {
        url = url + '?' + buildParameter (options ['data']);
    }
    request.open (method, url);
    if (method.toLowerCase() == 'get') {
        request.setRequestHeader ("Content-Type", "text/html;charset=utf-8");
    }
    request.onreadystatechange = function () {
        if (request.readyState == 4) {
            try {
                switch (request.status) {
                    case 200 :
/*
                        data = eval ('(' + request.responseText + ')');
                        loadImages ();
*/
                        if ('success' in options) {
                            var callback = options ['success'];
                            callback (request);
                        }
                        break;
                    case 403 :
/*
                        var container = document.getElementById ('browser');
                        container.innerHTML = '';
                        permission = false;
                        alert ('您没有权限访问私有目录');
*/
                        if ('error' in options) {
                            options ['error'] (403, request);
                        }
                        break;
                    case 404 :
                        alert ("找不到服务：" + url);
                        break;
                    case 405 :
                        alert ("Http Request Method [" + method + "] NOT ALLOWED!");
                        break;
                    case 406 :
                        alert (name + " is NOT a Jasmine Ajax Service!");
                        break;
                    default :
                        alert ('Unknown Error, response code: ' + request.status);
                        break;
                }
            } catch (E) {
//                alert (E);
                if ('error' in options) {
                    options ['error'] (0, request);
                }
            } finally {
/*
                var loading = document.getElementById ('loading-panel');
                if (loading) loading.style.display = 'none';
*/
                if ('always' in options) {
                    options ['always'] (request);
                }
            }
        }
    };
    if (method.toLowerCase() != 'get' && ('data' in options)) {
        request.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
        request.send (buildParameter (options ['data']));
    } else {
        request.send (null);
    }
};